/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ua.i.kotionokyurievna.jewelry.domain.user;

/**
 *
 * @author Kateryna_Reznik
 */
public class User implements UserI{
    private int userId;
    private String login;
    private String password;
    
    public User(){}
    
    public User( String login, String password){
        this.login = login;
        this.password = password; 
    }
    
    public User( int id, String login, String password){
        this.userId = id;
        this.login = login;
        this.password = password; 
    }

    public User( User another ) {
        if ( another != null ){
            this.userId = another.userId;
            this.login = another.login;
            this.password = another.password;
        }
    }
    
    public int getUserId() {
        return userId;
    }

    public String getLogin() {
        return login;
    }

    public void setLogin(String login) {
        this.login = login;
    }
    
    
    public boolean isLegalUser( String userPassword ){
        if ( userPassword != null && password != null ){
            if (userPassword.equals(password)){
                return true;
            }
        } 
        return false;
    }
    
    public boolean setPassword( String oldPassword, String newPassword ){
        if ( password.isEmpty() ){
            password = newPassword.substring(0);
            return true;
        }
        else{
            if ( !oldPassword.isEmpty() && (oldPassword.equals(password)) ) {
                password = newPassword.substring(0);
                return true;
            }
        }
        return false;
    }

    @Override
    public String toString() {
        return "User{" + "login=" + login + '}';
    }
    
    

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 61 * hash + (this.login != null ? this.login.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final User other = (User) obj;
        if ((this.login == null) ? (other.login != null) : !this.login.equals(other.login)) {
            return false;
        }
        return true;
    }
    
    
}
